package HomeWork;

import java.util.Scanner;

/**
 * @author 李孟琦
 * @version V1.0
 * @ProjectName:IntelliJ IDEA
 * @PackageName: HomeWork
 * @ClassName: Calculator
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @date 2019/9/29 11:27
 * @Copyright 李孟琦版板所有
 */
public class Calculator {
    //1. 教员要求张浩使用面对对象思想编写一个计算器(Calculator)，
    // 可以实现两个整数的加，减，乘，除运算。
    int num1, num2, choose;
    double sum;

    public double Addition() {
        sum = num1 + num2;
        return sum;
    }

    public double Subtraction() {
        sum = num1 - num2;
        return sum;
    }

    public double Multiplication() {
        sum = num1 * num2;
        return sum;
    }

    public double DivisionMethod() {
        sum = num1 / num2;
        return sum;
    }

    public void Result() {
        switch (choose) {
            case 1:
                System.out.print("加法为:" + Addition());
                break;
            case 2:
                System.out.print("减法为:" + Subtraction());
                break;
            case 3:
                System.out.print("乘法为:" + Multiplication());
                break;
            case 4:
                if (num2 != 0) {
                    System.out.print("除法为:" + DivisionMethod());
                }else {
                    System.out.print("被除数不能为0，程序结束!");
                }
                break;
            default:
                System.out.print("您输入有误，程序结束!");
                break;
        }
    }

    public static void main(String[] args) {
        Calculator newNum = new Calculator();
        Scanner input = new Scanner(System.in);
        System.out.print("请输入第一个整数:");
        newNum.num1 = input.nextInt();
        System.out.print("请输入第二个整数:");
        newNum.num2 = input.nextInt();
        System.out.println("请选择加减乘除:" + "1:加" + " " + "2:减" + " " + "3:乘" + " " + "4:除");
        newNum.choose = input.nextInt();
        newNum.Result();
    }
}
